#include "http_server.h"
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/address.hpp>
#include <cstdint>
#include <exception>

void CreateServletDispatch(HttpConnection::ptr connect)
{
    auto despatch = connect->getServletDispatch();
    despatch->addServlet("/hahaha",[](HttpConnection::RequestPtr request, HttpConnection::ResponsePtr response)->int32_t{
        response->set(HttpConnection::Field::content_type, "text/plain");
        boost::beast::ostream(response->body()) << "hahahahaha";
    });
}

int main()
{
    // boost::asio::io_context ioc;
    // HttpConnection::TCP::socket sock(ioc, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 8080));
    // HttpConnection::TCP::acceptor accept(ioc);
    // HttpConnection::ptr connect = std::make_shared<HttpConnection>(sock);

    try 
    {
        auto const address = boost::asio::ip::make_address("127.0.0.1");
        boost::asio::io_context ioc;
        HttpConnection::TCP::acceptor accept(ioc, {address, 8080});
        HttpConnection::TCP::socket socket(ioc);
        HttpConnection::HttpAccept(accept, socket);
        ioc.run();

    }catch(std::exception& e) 
    {
    
    }

    return 0;
}